﻿/// <reference path="../Scripts/jquery-1.7.2.js" />
/// <reference path="../aaa/jqueryExtensions.js" />
/// <reference path="../Scripts/qunit.js" />
/// <reference path="../Scripts/sinon-1.3.4.js" />
/// <reference path="../Scripts/sinon-qunit-1.0.0.js" />

$(function () {
    var apiMock;
    var viewModel;

    module("Given non empty array", {
        setup: function () {
            this.testArray = [
                "Apple",            // 0
                "Avocado",          // 1
                "Banana",           // 2
                "Blackberry",       // 3
                "Cherry",           // 4
                "Grape",            // 5
                "Grapefruit",       // 6
                "Kiwi",             // 7
                "Lemon",            // 8
                "Mandarine",        // 9
                "Mango",            // 10
                "Melon",            // 11
                "Watermelon",       // 12
                "Orange",           // 13
                "Peach",            // 14
                "Pear",             // 15
                "Plum",             // 16
                "Pineapple",        // 17
                "Raspberry",        // 18
                "Strawberry"        // 19
            ];
        }
    });

    test("When 'take' 3 elements, then 3 elements are returned", function () {
        var result = this.testArray.take(3);
        equal(result.length, 3);
        equal(result[0], "Apple");
        equal(result[1], "Avocado");
        equal(result[2], "Banana");
    });
    
    test("When 'take' more elements then length of array, then array is returned", function () {
        var result = this.testArray.take(100000);
        equal(result.length, this.testArray.length);
        equal(result[0], "Apple");
    });



    test("When 'skip' 3 elements, than length - 3 elements are returned", function () {
        var result = this.testArray.skip(3);
        equal(result.length, this.testArray.length - 3);
        equal(result[0], "Blackberry");
        equal(result[1], "Cherry");
        equal(result[2], "Grape");
    });

    test("When 'skip' more elements than array length, then epty array is returned", function () {
        var result = this.testArray.skip(100000);
        equal(result.length, 0);
    });

    test("When combine 'skip' and 'take', then paged result is returned", function () {
        var result = this.testArray.skip(3).take(2);
        equal(result.length, 2);
        equal(result[0], "Blackberry");
        equal(result[1], "Cherry");
    });

    test("When 'takeUpToMaxOrMin' and array contains more than maximum element, then minimum is returned", function () {
        var result = this.testArray.takeUpToMaxOrMin(3, 5);
        equal(result.length, 3);
        equal(result[0], "Apple");
        equal(result[1], "Avocado");
        equal(result[2], "Banana");
    });


    test("When 'takeUpToMaxOrMin' and array contains less or equal than maximum element, then limited array is returned", function () {
        var result = this.testArray.takeUpToMaxOrMin(3, 20);
        equal(result.length, 20);
        equal(result[0], "Apple");
        equal(result[1], "Avocado");
        equal(result[2], "Banana");
    }); 
});